package com.bxd.baodan.activity;

import android.view.View;
import android.widget.ImageView;

import com.google.gson.reflect.TypeToken;
import com.bxd.baodan.R;
import com.bxd.baodan.adapter.ViewHolder;
import com.bxd.baodan.app.JsonApi;
import com.bxd.baodan.item.GanHuoBean;
import com.bxd.baodan.util.GlideUtil;
import com.bxd.baodan.util.NetUtil;

import java.lang.reflect.Type;
import java.util.List;

public class GanHuoActivity extends BaseListActivity<GanHuoBean> {


    @Override
    protected int getActivityLayout() {
        return R.layout.pull_refresh_layout;
    }

    @Override
    protected void preDone() {
        setActionBarTitle("干货");
        autoRefresh();

    }

    @Override
    protected Type getTypeToken() {
        return new TypeToken<List<GanHuoBean>>() {
        }.getType();
    }

    @Override
    protected int getItemLayout() {
        return R.layout.gan_huo_item_1;
    }

    @Override
    protected void setNetUtil() {
        netUtil = new NetUtil(this, JsonApi.ARTICLE_LISTS);
        netUtil.setParams("catId", "275");
        netUtil.setParams("page", "1");
    }

    @Override
    protected void convert(ViewHolder holder, final GanHuoBean item) {

        if (holder.getPosition() == 0) {
            holder.getView(R.id.large_fly).setVisibility(View.VISIBLE);
            holder.getView(R.id.main).setVisibility(View.GONE);
            GlideUtil.loadImage(this, item.image, ((ImageView) holder.getView(R.id.iv_large)));

            holder.setText(R.id.title_head, item.title);

        } else {

            holder.getView(R.id.main).setVisibility(View.VISIBLE);
            holder.getView(R.id.large_fly).setVisibility(View.GONE);
            GlideUtil.loadImage(this, item.image, ((ImageView) holder.getView(R.id.image)));

            holder.setText(R.id.title, item.title);
            holder.setText(R.id.read, item.viewCount + "阅读");
            holder.setText(R.id.tag,item.category.name);

        }
        holder.getView(R.id.main_1).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                openActivity(WebViewPager.class, new String[]{"startUrl"}, new String[]{item.url});
            }
        });


    }

    @Override
    protected String getArrayStr(String json_data) {
        return "list";
    }
}
